home *** CD-ROM | disk | FTP | other *** search
/ The Programmer Disk / The Programmer Disk (Microforum).iso / xpro / tutor / pro17 / student.qb4 < prev   
Encoding:
Text File  |  1991-03-31  |  2.7 KB  |  87 lines

  1. 'STUDENT.QB4 - Illustrates the use of the TYPE/END TYPE statements and
  2. 'how they can make your life so much easier and uncomplicated!
  3.  
  4. 'From the GWBT10 (GW-BASIC Tutorial Series #10) 04/01/1991
  5. 'Program written by Richard G. Harper
  6.  
  7. TYPE StudentRecord                      'This replaces the FIELD #1,
  8.     StudName AS STRING * 18             '18 AS STUDNAME$,
  9.     StudID AS DOUBLE                    '8 AS STUDID$,
  10.     StudCC AS INTEGER                   '2 AS STUDCC$,
  11.     StudGPA AS SINGLE                   '4 AS STUDGPA$
  12. END TYPE
  13.  
  14. DIM SRecord AS StudentRecord            'Now we can just call the whole mess
  15.                                         'a SRecord...
  16.  
  17. OPEN "STUDENT.DAT" FOR RANDOM AS #1 LEN = 32
  18.  
  19. Start:
  20.     COLOR 6, 0, 0
  21.     CLS
  22.     PRINT "Press 'R' to read in a student's information from disk, 'W' to"
  23.     PRINT "enter and write a student's information to disk, or 'Q' to quit..."
  24. GetKey:
  25.     AA$ = INKEY$
  26.     IF AA$ = "Q" OR AA$ = "q" THEN
  27.         CLOSE
  28.         RESET
  29.         END
  30.     ELSEIF AA$ = "R" OR AA$ = "r" THEN
  31.         GOTO ReadRecord
  32.     ELSEIF AA$ = "W" OR AA$ = "w" THEN
  33.         GOTO WriteRecord
  34.     ELSE
  35.         GOTO GetKey
  36.     END IF
  37.  
  38. ReadRecord:
  39.     CLS
  40.     PRINT "To find a student's information on disk, I need you to give me the"
  41.     PRINT "Student ID code.  Please enter it below..."
  42.     PRINT
  43.     INPUT "Student ID: "; StudentID#
  44.     PRINT
  45.     PRINT "Looking, please wait..."
  46.     EN1 = LOF(1) / 32
  47.     FOR Record = 1 TO EN1
  48.         GET #1, Record, SRecord
  49.         IF StudentID# = SRecord.StudID THEN
  50.             PRINT "Information is as follows:"
  51.             PRINT "Student Last Name: "; SRecord.StudName
  52.             PRINT "Student ID Code  : "; SRecord.StudID
  53.             PRINT "Course Code      : "; SRecord.StudCC
  54.             PRINT "Student GPA      : "; SRecord.StudGPA
  55.         END IF
  56.     NEXT Record
  57.     PRINT "Search complete.  Press any key to continue..."
  58.     WHILE INKEY$ = "": WEND
  59.     GOTO Start
  60.  
  61. WriteRecord:
  62.     CLS
  63.     PRINT "Please provide the requested information below..."
  64.     PRINT
  65.     LINE INPUT "Student Last Name: "; SRecord.StudName
  66.     INPUT "Student ID Code  : "; SRecord.StudID
  67.     INPUT "Course Code      : "; SRecord.StudCC
  68.     INPUT "Student GPA      : "; SRecord.StudGPA
  69.     PRINT
  70.     PRINT "If all of the above are correct, press 'Y' to save to disk, or else"
  71.     PRINT "press 'N' to re-enter the information..."
  72. GetWriteKey:
  73.     AA$ = INKEY$
  74.     IF AA$ = "Y" OR AA$ = "y" THEN
  75.         EN1 = LOF(1) / 32
  76.         EN1 = EN1 + 1
  77.         PUT #1, EN1, SRecord
  78.         GOTO Start
  79.     ELSEIF AA$ = "N" OR AA$ = "n" THEN
  80.         GOTO WriteRecord
  81.     ELSE
  82.         GOTO GetWriteKey
  83.     END IF
  84.  
  85. 'End of program - STUDENT.QB4
  86.  
  87.